package com.idp.app.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.idp.common.base.BaseController;
import com.idp.common.model.PageModel;
import com.idp.common.model.ResultModel;
import com.idp.app.dto.SySjzdDto;
import com.idp.app.dto.SySjzdSearchDto;
import com.idp.app.service.SySjzdService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 数据字典表Controller
 * @author Simon
 */
@Api(tags="数据字典表")
@RestController
@RequestMapping("/sySjzd/")
public class SySjzdController extends BaseController {

	@Autowired
	private SySjzdService sySjzdService;

	/**
	 * 分页查询
	 * @param sySjzdSearchDto
	 * @return
	 */
	@ApiOperation(value="分页查询")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "page", value = "页数", paramType = "query", required = true, defaultValue = "1"),
		@ApiImplicitParam(name = "rows", value = "每页行数", paramType = "query", required = true, defaultValue = "10")
	})
	@PostMapping("findByPage")
	public ResultModel<PageModel<SySjzdDto>> findByPage(@RequestBody SySjzdSearchDto sySjzdSearchDto) {
		return ResultModel.success(sySjzdService.findByPage(sySjzdSearchDto));
	}

	/**
	 * 通过id查询
	 * @param sySjzdDto
	 * @return
	 */
	@ApiOperation(value="通过id查询")
	@ApiOperationSupport(includeParameters = {"sySjzdDto.id"})
	@PostMapping("getById")
	public ResultModel<SySjzdDto> getById(@RequestBody SySjzdDto sySjzdDto) {
		return ResultModel.success(sySjzdService.getById(sySjzdDto.getId()));
	}

	/**
	 * 新增
	 * @param sySjzdDto
	 * @return
	 */
	@ApiOperation(value="新增")
	@ApiOperationSupport(ignoreParameters = {"sySjzdDto.id"})
	@PostMapping("add")
	public ResultModel add(@RequestBody SySjzdDto sySjzdDto) {
		sySjzdService.add(sySjzdDto);
		return ResultModel.success("新增成功", null);
	}

	/**
	 * 修改
	 * @param sySjzdDto
	 * @return
	 */
	@ApiOperation(value="修改")
	@PostMapping("update")
	public ResultModel update(@RequestBody SySjzdDto sySjzdDto) {
		sySjzdService.update(sySjzdDto);
		return ResultModel.success("修改成功", null);
	}

	/**
	 * 删除
	 * @param sySjzdDto
	 * @return
	 */
	@ApiOperation(value="删除")
	@ApiOperationSupport(includeParameters = {"sySjzdDto.id"})
	@PostMapping("delete")
	public ResultModel delete(@RequestBody SySjzdDto sySjzdDto) {
		sySjzdService.delete(sySjzdDto.getId());
		return ResultModel.success("删除成功", null);
	}

}
